<style type="text/css">
	.page-shopping .bottom-panel{display: flex;}
	.page-shopping .bottom-panel .info{margin-top: 4px;width: 50%;}
	.page-shopping .bottom-panel .right{margin-top: 10px;}
  .page-shopping .item-list .attr span{overflow: hidden;display: -webkit-box; font-weight: normal; white-space: nowrap;}
  .lit-li{display: flex;padding:2px 0px;border-top:1px solid #eee;}
  .layui-layer-content div:first-child{border-top:0;}
  .lit-li .lit-pic{width:70px;text-align: center;}
  .lit-li .lit-pic img {width:50px;}
  .lit-li div{display: inline-block;}
  .lit-li .price .mar_price{font-size: 13px;text-decoration: line-through;color: #999;}
  .lit-li .price{min-width:90px;}
  .lit-li .price span{line-height: 13px;display: block;}
  .lit-li .lit-attr span{font-size:12px;color:#666;}
  .lit-li .cont{padding-left:5px;}
  .layui-layer-setwin{top:0;right:0;padding:15px 0px;width:40px;}
</style>
 <foreach name="cartList" item="va" key="k" >
    <div  class="block" style="margin-top:0px;">
      <div class="shop_title" >
        <div class="fl"><a class="shopLink eclipse" href="javascript:void(0);" style="font-weight: normal;color:#666;">供货商：{$va.suppliers_name}</a>
        <input type="hidden" name="supplierid" id="supplierid" value="7"></div>
      </div>   
      <div class="item-list">
      <volist name="va['icart_items']" id="v">
       <div class="item" sku-data="{$v.sku}" id="{$v.id}">
         <div class="inner">
           <div style="width:60%; float:left; height:88px;">
             <div class="check-wrapper">
                 <!--勾选按钮-->
              <span  class="cart-checkbox  <if condition="$v[selected] eq 1" >checked</if>">
                 <input type="checkbox" autocomplete="off" name="cart_select[{$v.id}]" <if condition="$v[selected] eq 1" >checked="checked"</if>  style="display:none;" value="1" onclick="ajax_cart_list();">
              </span>
             </div>
             <div  class="pic">
                 <a href="{:U('Mobile/Goods/goodsInfo',array('id'=>$v[goods_id]))}"><img src="{$v.goods_id|goods_thum_images=200,200}"></a>
             </div>
             <div class="name">
               <span>  {$v.goods_name} </span>
             </div>
             <div class="attr">
                 <span>{$v.spec_key_name}</span>
             </div>
             <div class="num">
                 <div class="xm-input-number">
                   <div class="act_wrap">
                      <a href="javascript:;" onclick="switch_num(-1,{$v.id},{$v.store_count});" id="jiannum6" class="input-sub active"></a>
                     	<input id="goods_num[{$v.id}]" type="text" onKeyDown='if(event.keyCode == 13) event.returnValue = false' name="goods_num[{$v.id}]"  value="<if condition='$v[goods_num] gt $v[store_count] and $v[store_count] neq 0'>{$v[store_count]}<elseif condition='$v[store_count] eq 0' />1<else />{$v[goods_num]}</if>"  class="input-num"  onblur="ajax_cart_list()"/>
                     	<a href="javascript:;" onclick="switch_num(1,{$v.id},{$v.store_count});"  class="input-add active"></a>
                     </div>
                  </div>
                   
             </div>
           </div>
           <div style=" position:absolute; right:0px; top:10px; width:100px; height:88px;">
             <div class="price">
               <span class="mar_price">￥{$v.market_price}元</span>
               <span class="mar_price">￥{$v.goods_price}元</span>
               <span>￥{$v.member_goods_price}元</span>
              </div>
             <div class="delete">
               <a href="javascript:void(0);" onclick="del_cart_goods({$v.id})">
                 <div class="icon-shanchu"></div>
               </a>
             </div>
           </div>
           <div style="height:0px; line-height:0px; clear:both;"></div>
         </div>
         <div class="append"></div>
       </div>
       </volist>
     </div>
    </div>

</foreach>
<if condition="empty($cartList)">         
<div class="screen-wrap fullscreen login">
<section id="cart-content">
      <div class="qb_tac" style="padding:50px 0">
        <img src="__STATIC__/images/flow/empty_cart.png" width="100" height="95">
        <br>购物车还是空的</div>
      <div class="qb_gap" style="width:60%; margin:0 auto;">
        <a href="{:U('Index/index')}" class="mod_btn btn_strong">马上逛逛</a>
      </div>
</section>
<div style="height:72px;"></div>
<section class="f_mask" style="display: none;"></section>
<section class="f_block" id="choose" style="height:0px;"></section> 
</div>
 <else/>
	 <div class="bottom-panel">
	    <div class="quanxuan">
	     <div class="check-wrapper">
	        <span class="cart-checkbox" onclick="chkAll_onclick()"></span><span class="cart-checktext">全选</span>
	     </div>
	   </div>
	   <div class="info">
	     <span class="hot" id="cart_amount_desc"><em>总计：</em>￥{$total_price.total_fee}元</span>
	     <br>
	     <span class="hot_text">不含运费</span>
	   </div>
	   <div class="right">
	     <input type="button" href="javascript:void();"  onclick="return selcart_submit();" class="xm-button " value="去结算"></div>
	</div>
</if> 
<script type="text/javascript">
    //选择商品
$(".check-wrapper .cart-checkbox").click(function(){
	if($(this).hasClass('checked')){
		$(this).removeClass('checked');
		$(this).find('input').attr('checked',false);
	}else{
		$(this).addClass('checked');
		$(this).find('input').attr('checked',true);
	}
	ajax_cart_list();
})

//定义变量
var is_checked = true;
$('.inner .cart-checkbox').each(function(){
        //判断商品是否选中
	  if(!$(this).hasClass('checked'))
	  {
	       is_checked = false;
	       return false;
	  }
});
if(is_checked){
  	$('.quanxuan .cart-checkbox').addClass('checked'); 
}else
{
  	$('.quanxuan .cart-checkbox').removeClass('checked'); 
} 


function chkAll_onclick() 
{

    //  取消
  if($('.quanxuan .cart-checkbox').hasClass('checked')){

    $('.quanxuan .cart-checkbox').removeClass('checked');
    $('.inner .cart-checkbox').removeClass('checked');
    $("input[name^='cart_select']").prop('checked',false);
    is_checked = false;
  }
  //全选
  else{
    $('.quanxuan .cart-checkbox').addClass('checked');
    $('.inner .cart-checkbox').addClass('checked');
    $("input[name^='cart_select']").prop('checked',true);
    is_checked = true;
  }
  ajax_cart_list();
}

function del_cart_goods(goods_id)
{
    if(!confirm('确定要删除吗?'))
        return false;
    var chk_value = [];
    chk_value.push(goods_id);
    // ajax调用删除
    if(chk_value.length > 0)
        ajax_del_cart(chk_value.join(','));
}


//点击结算
function selcart_submit()
{
   var index = layer.load(1, {
     shade: [0.1,'#fff'] //0.1透明度的白色背景
   });
    //获取中的商品数量
     var j=0,k=0;
     var htmlstr='';
	 $('input[name^="cart_select"]:checked').each(function(){
	       j++;
         var sku=$(this).parents('.item').attr('sku-data');
         var b_num=$(this).parents('.inner').find('.input-num').val();
         var pic=$(this).parents('.inner').find('.pic').html();
         var title=$(this).parents('.inner').find('.name').html();
         var attr=$(this).parents('.inner').find('.attr').html();
         var price=$(this).parents('.inner').find('.price').html();
         $.post('{:U("Goods/sync_store")}',{type:'sku',sku:sku},function(res){
            if(res!=''&&res!='null'){
              var obj=jQuery.parseJSON(res);
              var current_num=obj.current_num;
              if(current_num<b_num){
                  htmlstr+='<div class="lit-li"><div class="lit-pic">'+pic+'</div><div class="cont"><div class="lit-title">'+title+'</div><div class="lit-attr">'+attr+'</div></div><div class="price">'+price+'</div></div>';
              }
            }
               
             k++;
             ajaxcompelet(j,k,htmlstr);
         })

	 });

   if (j==0) {
    layer.closeAll();
    layer.msg('请选择要结算的商品！');
   }

 
}

function ajaxcompelet(j,k,htmlstr){
  if(j==k){
    if(htmlstr!=''){
        layer.closeAll();
         layer.open({
           type: 1,
           title: '以下商品库存不足',
           skin: 'layui-layer-rim', //加上边框
           area: ['80%', '220px'], //宽高
           content: htmlstr
         });
         $('.layui-layer-setwin').click(function(){
          layer.closeAll();
         })
         return false;
      }
        layer.closeAll();
        window.location.href="{:U('Mobile/Cart/cart2')}"
       
  }

}
</script>